package com.zhibang.sinocare.user.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zhibang.sinocare.common.domian.vo.SystemAccountListVo;
import com.zhibang.sinocare.common.result.Result;
import com.zhibang.sinocare.common.result.ResultCode;
import com.zhibang.sinocare.user.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/UserRole")
@Api(tags = "用户模块，用于检测者、门店账户的CRUD及其业务，包括认证授权。" , description = "对页面进行CRUD操作")
@CrossOrigin
public class UserController {

    @Resource
    private UserServiceImpl userServiceImpl;

    /**
     * 分页查询
     * @param page
     * @param limit
     * @param searchParams
     * @return
     * @throws Exception
     */
    @RequestMapping("find")
    @ApiOperation(value = "查询用户账号信息" ,notes = "根据条件查询数据" , httpMethod = "GET")
    public Result query(@RequestParam(value = "page" ,defaultValue = "1") Integer page , @RequestParam(value = "limit" ,defaultValue = "5") Integer limit, String searchParams) throws Exception{
        System.out.println("进入find方法");
        System.out.println("dsfs"+searchParams);
        ObjectMapper objectMapper = new ObjectMapper();
        SystemAccountListVo listVo = null;
        if (searchParams != null && !"".equals(searchParams)){
            listVo = objectMapper.readValue(searchParams,SystemAccountListVo.class);
        }
        Page page1 = PageHelper.startPage(page,limit);
        List<SystemAccountListVo> systemAccountListVos = userServiceImpl.queryBy(listVo);
        return Result.ok(ResultCode.SUCCESS,page1.getTotal(),systemAccountListVos);
    }
}
